-
Notifications
You must be signed in to change notification settings - Fork 23
OpenAPI oneOf support #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
...openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/Order.java
Outdated
Show resolved
Hide resolved
...anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/RootObjectQuestionsInner.java
Outdated
Show resolved
Hide resolved
...pi-generator/src/test/resources/DataModelGeneratorIntegrationTest/oneof/input/sodastore.yaml
Outdated
Show resolved
Hide resolved
| /** | ||
| * Generate model classes. Default is true. | ||
| */ | ||
| @Parameter( property = "openapi.generate.generateModels", defaultValue = "true" ) | ||
| private boolean generateModels; | ||
|
|
||
| /** | ||
| * Generate API classes (client classes). Default is true. | ||
| */ | ||
| @Parameter( property = "openapi.generate.generateApis", defaultValue = "true" ) | ||
| private boolean generateApis; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Question)
Why not have this as separate PR? It's unrelated to oneof / anyof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to save time
...ator/src/test/resources/DataModelGeneratorIntegrationTest/generate-apis/input/sodastore.yaml
Outdated
Show resolved
Hide resolved
| true, | ||
| 6, | ||
| Map.of("useOneOfInterfaces", "true")), | ||
| GENERATE_APIS( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Comment)
Not really sure, whether it's good to mix testing scopes of generate-api and anyof/allof/oneof.
But I'm not objecting at this point. You're just reusing the same spec file.
release_notes.md
Outdated
|
|
||
| - Add support for `TypeDefinition` entries in OData V4 EDMX files. | ||
| - OpenAPI generator improvements: | ||
| - Add `oneOf`, `anyOf` and `allOf` support for OpenAPI generation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Major)
I'll check the PR in AI SDK, but still it would be good to have a proper unit test in this repo, checking whether serialization and deserialization works at runtime. We are not even testing whether compilation works, right?
Otherwise, looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for compilation in the sample
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this is a hidden feature in the additional parameters. It should receive the same tests as your pojoBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for compilation in the sample
Please link the sample that is being compiled.
this is a hidden feature in the additional parameters
I think this is incorrect, "enableOneOfAnyOfGeneration" is a well documented, publicly suggested and already used feature. It's not considered hidden compared to the pojoBuilder.
If we claim new and better support for oneof, anyof and allof - then we should have them tested for deserialization/serialization. If I see correctly the openapi-api-sample module only tests for allof currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't change enableOneOfAnyOfGeneration but I added useOneOfInterfaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can see that the existing Test/input-spec-with-anyof-oneof/RootObjectQuestionsInner.java didn't change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's somewhat odd to add useOneOfInterfaces in addition to enableOneOfAnyOfGeneration. It somewhat hides this new functionality from users. How much of a breaking change would it be to always enable the interfaces when enableOneOfAnyOfGeneration is defined?
Also agreeing with @newtork: We need tests in the sample code to ensure compilation actually works. Integration testing this isn't sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a deserialization test in the sample app
MatKuhr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments, most importantly though I think we need a compilation and a runtime check, i.e. sample code and test assertions on (de-) serialization
...or/src/test/resources/DataModelGeneratorIntegrationTest/generate-apis/output/test/OneOf.java
Show resolved
Hide resolved
...ator/src/test/resources/DataModelGeneratorIntegrationTest/generate-apis/input/sodastore.yaml
Show resolved
Hide resolved
...odelGeneratorIntegrationTest/generate-apis/output/test/OneOfWithDiscriminatorAndMapping.java
Show resolved
Hide resolved
...anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/RootObjectQuestionsInner.java
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,63 @@ | |||
| openapi: 3.0.0 | |||
| info: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have this spec file twice now? Also, why not re-use the existing DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/input/AggregatorNestedSchemaChild.json ?
I know we already have a rather bloated test setup here, with much duplication, but adding more to it will cause PR diffs to get larger and larger..
| </executions> | ||
| <configuration> | ||
| <inputSpec>${project.basedir}/src/main/resources/sodastore.json</inputSpec> | ||
| <inputSpec>${project.basedir}/src/main/resources/sodastore.yaml</inputSpec> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Question)
Why did you change from json to yaml?
Only for flavor, or does anyof/oneof not work for json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flavor, the file is shorter
...e/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java
Show resolved
Hide resolved
...e/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java
Show resolved
Hide resolved
Co-authored-by: Alexander Dümont <[email protected]>
MatKuhr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise lgtm
| /** | ||
| * OneOfWithDiscriminatorAndMapping | ||
| */ | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, this shouldn't be there, since it leads to "@type" fields during serialisation. In the AI SDK this is manually suppressed via mixins. It would be better to not generate this or mark it as disabled. Regardless of what we do, probably a serialisation test would be good
Context
AI/ai-sdk-java-backlog#112
oneOf / anyOf / allOf with multiple possible options should form an interface or a class that is able to parse those multiple options
openAPI templates were updated to 7.8.0
Feature scope:
Definition of Done
Error handling created / updated & covered by the tests above